$package('itsm.business');

itsm.business.buyIng=function(){
	this.opt='';
	return {
		//列表
		buyIngGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'buy!findBuyPage.action?buyQueryDTO.searchType=MatchIng&buyQueryDTO.multipleStatus=0&buyQueryDTO.multipleStatus=1',
				caption:'买入列表',
				colNames:['ID','买入会员','姓名','买入时间','买入金额','状态','匹配日期','剩余买入金额','优先级','已排队(天)','已分红(天)','已分红','分红利息','分红封顶'],
			 	colModel:[
			 	          {name:'id',align:'center',width:80},
			 	          {name:'buyUser',align:'center'},
			 	          {name:'buyUserName',align:'center',hidden:true},
			 	          {name:'createTime',align:'center',formatter:timeFormatter},
			 	          {name:'dBuyMoney',align:'center'},
			 	          {name:'status',align:'center',formatter:itsm.business.buyIng.statusFormatter},
			 	          {name:'matchTime',align:'center',formatter:timeFormatter},
			 	          {name:'dSurplusMoney',align:'center'},
			 	          {name:'priority',align:'center'},
			 	          {name:'crateTime',align:'center',hidden:true},
			 	          {name:'crateTime',align:'center',hidden:true},
			 	          {name:'crateTime',align:'center',hidden:true},
			 	          {name:'crateTime',align:'center',hidden:true},
			 	          {name:'crateTime',align:'center',hidden:true}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'id',
				toolbar:[true,"top"],
				sortorder:'desc',
				rowNum:20, 
				rowList:[10,20,50],
				pager:'#buyIngPager'
				});
				$("#buyIngGrid").jqGrid(params);
				$("#buyIngGrid").navGrid('#buyIngPager',navGridParams);
				//列表操作项
				$("#t_buyIngGrid").css(jqGridTopStyles);
				$("#t_buyIngGrid").html($('#buyIngGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#buyIngGrid","regCenter",10);
		},
		statusFormatter:function(v1,v2,v3){
			if(v1=='0'){
				return "<span style='color:#0000EE'>排队中</span>";
			}
			if(v1=='1'){
				return "<span style='color:#8A2BE2'>匹配成功</span>";
			}
			if(v1=='2'){
				return "<span style='color:#228B22;'>交易成功</span>";
			}
			if(v1=='3'){
				return "<span style='color:#EEC900;'>已取消</span>";
			}
		},
		
		changeOrder:function(v1,v2,v3){
			checkBeforeEditGrid('#buyIngGrid',function(rowData){
				$('#buy_id').val(rowData.id);
				$('#buy_priority').val(rowData.priority);
				$('#buy_createDate').val(rowData.createTime);
				$('#changeBuyOrder_win').window('open');
			});	
		},
		
		changeOrderOpt:function(){
			var _param = $('#changeBuyOrder_form').serialize();
			$.post('buy!changeOrder.action',_param,function(data){
				msgShow('更新成功!','show');
				$('#changeBuyOrder_win').window('close');
				$('#buyIngGrid').trigger('reloadGrid');
			})
		},
		
		//搜索
		searchBuy:function(){
			var sdata=$('#buy_search_form').getForm();
			var postData = $("#buyGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'buy!findBuyPage.action';
			$('#buyGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		openEditOrder:function(v1,v2,v3){
			checkBeforeEditGrid('#buyIngGrid',function(rowData){
				$('#editbuy_id').val(rowData.id);
				$('#edit_buyPrice').val(rowData.buyPrice);
				$('#edit_buyMoney').val(rowData.buyMoney);
				$('#editBuyOrder_win').window('open');
			});	
		},
		editOrderOpt:function(){
			var _param = $('#editBuyOrder_form').serialize();
			$.post('buy!changeOrder.action',_param,function(data){
				msgShow('更新成功!','show');
				$('#editBuyOrder_win').window('close');
				$('#buyIngGrid').trigger('reloadGrid');
			})
		},
		init:function(){
			itsm.business.buyIng.buyIngGrid();
		}
	}
	
}();

$(function(){
	itsm.business.buyIng.init();
});